<template>
  <el-col :span="24" >
    <el-form ref="form2" :model="form" label-width="80px" @submit.prevent style="margin:20px;width:60%;min-width:600px;">
      <el-form-item label="模块名称">
        <el-select v-model="form.id" placeholder="请选择模块" @change="anselect">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="banner图" v-show="anshow">
        <!--<el-input v-model="form.src" :disabled="true"></el-input>-->
        <div class="show">
          <img :src="imgheaderImage" alt="Picture">
          <!--<div class="picture" :style="'backgroundImage:url('+imgheaderImage+')'"></div>-->
        </div>
        <cropper :imginfo="imginfo" @get-img="getimgdata"></cropper>
      </el-form-item>
      <el-form-item label="模块内容" v-show="anshow">
        <el-input type="textarea" :autosize="{ minRows: 15, maxRows: 50}" v-model="form.txt"></el-input>
      </el-form-item>
      <el-form-item v-show="anshow">
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button @click.native.prevent>取消</el-button>
      </el-form-item>
    </el-form>
  </el-col>
</template>


<script>
  import { selecttxt,selecttxtupdata,bannerupdata } from '@/api/wxdata'
  import Cropper from '@/components/Cropper'
  export default {
    components: {
      Cropper
    },
    data() {
      return {
        form: {
          id: '',
          src:'banner.jpg',
          tile:'',
          txt: ''
        },
        options:[
          { label: '月嫂服务' ,value: '1'},
          { label: '育婴师', value: '2'},
          { label: '住家保姆', value: '3'},
          { label: '家庭保洁', value: '4'},
          { label: '钟点工服务', value: '5'},
          { label: '白班育婴师', value: '6'},
          { label: '钟点保洁', value: '7'},
          { label: '相关服务', value: '8'},
        ],
        anshow:false,
        imginfo:{
          imgaspectRatio:2/1, //剪裁图片比例
          imgwidth:400
        },
        imgheaderImage:"" //剪裁后的图片
      }
    },
    methods: {
      onSubmit() {
        let senddata = this.form;
        senddata['imgdata'] = this.imgheaderImage;
        selecttxtupdata(senddata).then(response => {  //上传数据
          this.$message.success(response.msg);
          this.anselect()
        })
      },
      anselect(){
        selecttxt(this.form.id).then(response => {
          this.form = response.data;
          this.anshow = true;
          this.imgheaderImage = "http://www.anranweb.cn/wximages/"+this.form.src
        })
      },
      getimgdata(value){
        this.imgheaderImage = value;
      }
    }
  }
</script>


<style scoped>
  .show {
    width: 400px;
    height: 200px;
    overflow: hidden;
    position: relative;
    border: 1px solid #d5d5d5;
    margin-bottom: 15px;
  }
  .show img{
    width:100%;
  }

  .el-col{ margin-bottom:15px; padding-bottom:15px;}
  .an-imgbox{ width: 150px; height: 150px; float: left; margin: 5px 8px; position: relative;}
  .an-color{color:#e9af00;}
</style>
